package br.com.cogerh.sidec.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

import javax.annotation.PostConstruct;
import br.com.cogerh.sidec.view.CompromissoRN;


public class job {
	
	@PostConstruct
public void preparaJob() {
		final CompromissoRN compromissoRN = new CompromissoRN();
		
		
	 Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 1);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.getTimeInMillis();

    final Calendar c1 = Calendar.getInstance();
    c1.getTimeInMillis();
  

    final long resu;
    if(c.getTimeInMillis() >= c1.getTimeInMillis()){
   	 resu = c.getTimeInMillis() -  c1.getTimeInMillis();	
    }else{
   	 resu = c1.getTimeInMillis() - c.getTimeInMillis();
    }
    
    final Timer t = new Timer();
   t.schedule(new TimerTask() {
       @Override
       public void run() {
         
			try {
				compromissoRN.enviaEmailPeriodico();

				compromissoRN.atualizaCoresCompromisso();
				
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
     
        }
   },resu,86400000);
}
	public void atualizarCores(){
		 CompromissoRN compromissoRN = new CompromissoRN();
		try {
			compromissoRN.atualizaCoresCompromisso();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	
	
}
